package edu.hawaii.wattwaiter.page.gridinfo;

import java.util.ArrayList;
import java.util.List;
import org.wattdepot.client.BadXmlException;
import org.wattdepot.client.MiscClientException;
import org.wattdepot.client.NotAuthorizedException;
import org.wattdepot.client.WattDepotClient;
import org.wattdepot.resource.source.jaxb.Source;

/**
 * Queries wattdepot for list of sources.
 * @author Remy
 *
 */
public class PopulateSources {

  /**
   * Gets the sources.
   * @return list sources
   */
  public List<String> getSources() {
    WattDepotClient client = new WattDepotClient("http://server.wattdepot.org:8182/wattdepot/");
    List<String> sourceList = new ArrayList<String>();

    try {
      List<Source> sources = client.getSources();
      for (Source source : sources) {
        sourceList.add(source.getName());
      }

    }
    catch (NotAuthorizedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    catch (BadXmlException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    catch (MiscClientException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    return sourceList;
  }

}
